$(function() {
		var tsId =null;
		var tsName = null;
		var error_Detail = null;
		tips = $(".validateTips");
        /*上方错误提示语句*/
		function updateTips(t) {
			tips
				.text(t)
				.addClass('ui-state-highlight');
			setTimeout(function() {
				tips.removeClass('ui-state-highlight', 1500);
			}, 500);
		}
		
		
		$("dialog").dialog("destory");
		/*增加记录框*/
		$("#dialog_add").dialog( {
			autoOpen : false,
			width : 300,
			modal : true,
			buttons : {
				'增加' : function() {				
					var cArr = $.trim($("textarea[name='tsName_add']").val()).match(/[^x00-xff]/ig);
					(cArr == null ? 0:cArr.length);　　
					if(($.trim($("textarea[name='tsName_add']").val()).length+(cArr == null ? 0:cArr.length))>100)
					{
						updateTips("数据过长，不超过50个汉字");
						$("textarea[name='tsName_add']").focus();
					}
        	
					else if($.trim($("textarea[name='tsName_add']").val()) != ""){
						//$("button[name='增加']").attr("disabled","true");
        				$("#add_confirm").dialog("open");
        			}
        			else{
        				updateTips("数据不可为空，请输入数据");
        				$("textarea[name='tsName_add']").focus();
        			}
				},
				'取消' : function() {
					$(this).dialog('close');
				}
			},
			close : function() {
				$("dialog").dialog("close");
			}
		});

		/*修改记录框*/
		$("#dialog_modify").dialog( {
			autoOpen : false,
			width : 300,
			modal : true,
			buttons : {
				'修改' : function() {
					var cArr = $.trim($("textarea[name='tsName_modify']").val()).match(/[^x00-xff]/ig);
					(cArr == null ? 0:cArr.length);　　
					if(($.trim($("textarea[name='tsName_modify']").val()).length+(cArr == null ? 0:cArr.length))>100)
					{
						updateTips("数据过长，不超过50个汉字");
						$("textarea[name='tsName_modify']").focus();
					}
	     	
					else if($("textarea[name='tsName_modify']").val()==tsName || $.trim($("textarea[name='tsName_modify']").val()) == ""){
						    updateTips("数据未改变或数据为空，请重新检查所输数据");
							$("textarea[name='tsName_modify']").focus();
						}
						    						
					else {          	
						$("#modify_confirm").dialog('open');						            			      				
					}
				},
				'取消' : function() {
					$(this).dialog('close');
				}
			},
			close : function() {
				$("dialog").dialog("close");
			}
		});

		/*修改记录确认*/
		$("#modify_confirm").dialog({
			autoOpen : false,
			resizable: false,
			modal: true,
			buttons: {
				'确定': function() {
							       	     						      		
        			var url = "zrt/update_task_status.action";
        			var new_tsName = $("textarea[name='tsName_modify']").val();
        			var req = {tsId:tsId,tsName:new_tsName};
        			$.post(url,req,function(data){
        				error_detail = $.trim(data.errorDetail);
        				if(error_detail == "") {
        					//alert(data.msg);
        					$("span[id='succ_msg']").text(data.msg);
        					$("#modify_confirm").dialog('close');
        					$("#operation_succ").dialog('open');
        				}
        				else {
        					//alert(data.msg);
							$("span[id='fail_msg']").text(data.msg);
							$("#operation_fail").dialog('open');
        				}
        			});            			      				
        	        		       	          	
				},
				'取消': function() {
					$(this).dialog('close');
				}
			}
		});

		/*增加记录确认*/
		$("#add_confirm").dialog({
			autoOpen : false,
			resizable: false,
			modal: true,
			buttons: {
				'确定': function() {			
			
					var url = "zrt/add_task_status.action";
					var req = {tsName:$.trim($("textarea[name='tsName_add']").val())};
					$.post(url,req,function(data){
						//alert(data.msg);
						error_detail = $.trim(data.errorDetail);
						if($.trim(data.errorDetail) == "") {
							//alert(data.msg);
							$("span[id='succ_msg']").text(data.msg);
							$("#add_confirm").dialog('close');
							$("#operation_succ").dialog('open');
						}
						/*操作失败*/
						else {
							//alert(data.msg);
							$("span[id='fail_msg']").text(data.msg);						
							$("#operation_fail").dialog('open');
						}
					});				       	       			      	          	
				},
				'取消': function() {
					$(this).dialog('close');
				}
			}
		});

		/*删除记录框确认*/
		$("#delete_confirm").dialog({
			autoOpen : false,
			resizable: false,
			modal: true,
			buttons: {
				'确定': function() {			
							         	                     
	               var url="zrt/delete_task_status.action";
	               var req={tsId:tsId};
	               $.post(url,req,function(data){   
	            	   error_Detail = $.trim(data.errorDetail);
						if($.trim(data.errorDetail) == "") {
							//alert(data.msg);
							$("span[id='succ_msg']").text(data.msg);
							$("#delete_confirm").dialog('close');
							$("#operation_succ").dialog('open');
						}
						/*操作失败*/
						else {
							//alert(data.msg);
							$("span[id='fail_msg']").text(data.msg);						
							$("#operation_fail").dialog('open');
						}
	               });	               	                			      		     		        			      				       	        		       	          	
				},
				
				'取消': function() {
					$(this).dialog('close');
				}
			}
		});

		/*操作成功框*/
		$("#operation_succ").dialog({
			autoOpen : false,
			resizable: false,
			modal: true,
			buttons: {
				'确定': function() {
					location.href="/ag/zrt/find_task_status.action";   	     						      		   	          	
				}
			}
		});
		
		/*操作失败 框*/
		$("#operation_fail").dialog({
			autoOpen : false,
			resizable: false,
			modal: true,
			buttons: {
				'确定': function() {
					//$("button[name='增加']").attr("disabled","true");
					$("#operation_fail").dialog('close');
					$("#add_confirm").dialog("close");
					
					//location.href="/ag/zrt/find_event_level.action";   	     						      		   	          	
				},
				'详细':function(){
					$("span[id='fail_detail']").text(error_detail);
					$("#operation_fail_detail").dialog('open');
				}
			},
			close:function(){
				$("#add_confirm").dialog("close");
				$("#modify_confirm").dialog("close");
				$("#delete_confirm").dialog("close");
			}
		});
		
		/*操作失败之详细信息框*/
		$("#operation_fail_detail").dialog({
			autoOpen : false,
			resizable: false,
			modal: true,
			buttons: {
				'关闭': function() {
					$("#operation_fail_detail").dialog('close');						      		   	          	
				}			
			}
		});
		
		/*打开增加框*/
		$("button[class='add']").click(function() {
			tips.text("带*为必填项");
			$('#dialog_add').dialog('option','width','300');
			if($.browser.mozilla)
				$('#dialog_add').dialog('option','height','300');
			$('#dialog_add').dialog('open');
			$("textarea[name='tsName_add']").focus();
		});
		/*打开修改框*/
		$("button[class='modify']").click(function() {
			tips.text("带*为必填项");
			tsId = $.trim($(this).parent().prev().prev().text());
			tsName = $.trim($(this).parent().prev().text());
			$("input[name='tsId_modify']").val(tsId);
			$("textarea[name='tsName_modify']").val(tsName);
			$('#dialog_modify').dialog('option','width','300');
			if($.browser.mozilla)
				$('#dialog_modify').dialog('option','height','300');
			$('#dialog_modify').dialog('open');
			$("textarea[name='tsName_modify']").focus();
		});	

		$("button[class='delete']").click(function() {
			tsId = $.trim($(this).parent().prev().prev().prev().text());
			$('#delete_confirm').dialog('open');
		});	
		
		/*加载按钮图片*/
		$("button[class='modify']").css("background","url('/ag/zrt/images/modify_mouseout.gif')");
		$("button[class='modify']").mouseover(function(){
			$(this).css("background","url('/ag/zrt/images/modify_mouseover.gif')");
		})
		.mouseout(function(){
			$(this).css("background","url('/ag/zrt/images/modify_mouseout.gif')");
		})
		.mousedown(function(){
			$(this).css("background","url('/ag/zrt/images/modify_mousedown.gif')");
		})
		.mouseup(function(){
			$(this).css("background","url('/ag/zrt/images/modify_mouseover.gif')");
		});

		$("button[class='delete']").css("background","url('/ag/zrt/images/delete_mouseout.gif')");
		$("button[class='delete']").mouseover(function(){
			$(this).css("background","url('/ag/zrt/images/delete_mouseover.gif')");
		})
		.mouseout(function(){
			$(this).css("background","url('/ag/zrt/images/delete_mouseout.gif')");
		})
		.mousedown(function(){
			$(this).css("background","url('/ag/zrt/images/delete_mousedown.gif')");
		})
		.mouseup(function(){
			$(this).css("background","url('/ag/zrt/images/delete_mouseover.gif')");
		});

		$("button[class='add']").css("background","url('/ag/zrt/images/add_mouseout.gif')");
		$("button[class='add']").mouseover(function(){
			$(this).css("background","url('/ag/zrt/images/add_mouseover.gif')");
		})
		.mouseout(function(){
			$(this).css("background","url('/ag/zrt/images/add_mouseout.gif')");
		})
		.mousedown(function(){
			$(this).css("background","url('/ag/zrt/images/add_mousedown.gif')");
		})
		.mouseup(function(){
			$(this).css("background","url('/ag/zrt/images/add_mouseover.gif')");
		});

		$("button[class='return']").css("background","url('/ag/zrt/images/return_mouseout.gif')");
		$("button[class='return']").mouseover(function(){
			$(this).css("background","url('/ag/zrt/images/return_mouseover.gif')");
		})
		.mouseout(function(){
			$(this).css("background","url('/ag/zrt/images/return_mouseout.gif')");
		})
		.mousedown(function(){
			$(this).css("background","url('/ag/zrt/images/return_mousedown.gif')");
		})
		.mouseup(function(){
			$(this).css("background","url('/ag/zrt/images/return_mouseover.gif')");
		}).click(function(){
			location.href="/ag/base_manage.jsp";
		});

		/*变色*/
		/*$("tr.list").mouseover(function() {
			$(this).children().css("background-color", "#66FFFF");
		}).mouseout(function() {
			$(this).children().css("background-color", "white");
		});*/
	});